package com.hanserwei.han_picture.enums;

import cn.hutool.core.util.ObjUtil;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * 空间级别枚举
 */
@Getter
public enum SpaceLevelEnum {
    COMMON("普通版", 0, 200, 150L * 1024 * 1024), // 150MB
    PROFESSIONAL("专业版", 1, 1500, 1024L * 1024 * 1024), // 1GB
    FLAGSHIP("旗舰版", 2, 20000, 10240L * 1024 * 1024), // 10GB
    ;

    private final String text;

    private final Integer value;

    private final long maxCount;

    private final long maxSize;

    SpaceLevelEnum(String text, Integer value, long maxCount, long maxSize) {
        this.text = text;
        this.value = value;
        this.maxCount = maxCount;
        this.maxSize = maxSize;
    }

    private static final Map<Integer, SpaceLevelEnum> VALUE_MAP = new HashMap<>();

    static {
        for (SpaceLevelEnum anEnum : SpaceLevelEnum.values()) {
            VALUE_MAP.put(anEnum.value, anEnum); // anEnum.value: 0/1/2
        }
    }

    /**
     * 根据 "0、1、2" 获得枚举对象
     *
     * @param value "0、1、2"
     * @return 对应的枚举对象
     */
    public static SpaceLevelEnum getEnumByValue(Integer value) {
        if (ObjUtil.isEmpty(value)) {
            return null;
        }
        return VALUE_MAP.get(value);
    }
}